package net.lahuobao.mall.service.impl.admin;

import net.lahuobao.mall.entity.admin.MallRegionEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.lahuobao.mall.service.admin.MallRegionServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;

import java.util.ArrayList;
import java.util.List;

@Service("mallRegionService")
@Transactional
public class MallRegionServiceImpl extends CommonServiceImpl implements MallRegionServiceI {

    @Override
    public String getAddressByCode(Integer code) {
        String str = "";
        MallRegionEntity regionEntity = super.findUniqueByProperty(MallRegionEntity.class, "id", String.valueOf(code));
        //父节点不等于id
        String parentId = regionEntity.getParentId();
        List<String> list = new ArrayList<String>();
        list.add(regionEntity.getRegionName().trim()+"_"+regionEntity.getId());
        while (!"100000".equals(parentId)){
            MallRegionEntity temp = super.findUniqueByProperty(MallRegionEntity.class, "id", parentId);
            parentId = temp.getParentId();
            list.add(temp.getRegionName().trim()+"_"+temp.getId());
        }
        for(int i = list.size() - 1; i >= 0; i--){
            if(i == 0){
                str += list.get(i);
            }else{
                str += list.get(i) + ";";
            }
        }
        return str;
    }
}